package com.fitness.front.controller;

import cn.hutool.http.HttpStatus;
import com.fitness.front.exception.BizException;
import com.fitness.front.modal.response.ServerResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
//@ControllerAdvice
public class ExceptionHandlerAdvice {

    @ExceptionHandler(value = BizException.class)
    public ServerResponseEntity<?> bizExceptionHandler(BizException e){
        log.error("bizException:{}",e.getMessage());
        return ServerResponseEntity.fail(HttpStatus.HTTP_INTERNAL_ERROR,e.getMessage());
    }

    @ExceptionHandler(value =Exception.class)
    public ServerResponseEntity<?> exceptionHandler(Exception e){
        log.error(e.getMessage());
        return ServerResponseEntity.fail(HttpStatus.HTTP_INTERNAL_ERROR,"服务器开小差了，请稍后再试！");
    }
}
